
var postsData = require('../../../data/posts-data.js')
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {

  
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


    var globalData = app.globalData;

    var postId = options.postId;
    this.data.currentPostId = postId;
   
    var postData = postsData.postList[postId];

  
    this.setData({
      
      postData:postData
    });

 
    var postsCollection = wx.getStorageSync('postsCollection')
    if (postsCollection) {
      var postCollection = postsCollection[postId];
      if (!postCollection) {
        postsCollection[postId] = false;
        wx.setStorageSync('postsCollection', postsCollection)
      }
      else {
        this.setData({
          collected: postCollection
        });
      }

    }
    else {
      postsCollection = {};
      postsCollection[postId] = false;
      wx.setStorageSync('postsCollection', postsCollection);
    }




  },

  onCollectionTap:function(event){

    var postsCollected = wx.getStorageSync("postsCollection");
    var postCollected = postsCollected[this.data.currentPostId];
    postCollected = !postCollected;
    postsCollected[this.data.currentPostId] = postCollected;
    wx.setStorageSync("postsCollection", postsCollected);
    this.setData({

      collected:postCollected
    })
  
   wx.showToast({
     

     title:postCollected?"收藏成功":"取消成功",
     duration:1000,
     icon:"success"

  
   })

  },
  onShareTap:function(event){
   
   wx.showActionSheet({
     itemList: [
   "分享给微信好友",
   "分享到朋友圈",
   "分享到微博",
   "分享到qq"

     ],
     itemColor:"#405f80",
     success:function(res){



     }
   })


  },


  onMusicTap:function(event){
  var currentPostId =  this.data.currentPostId
  wx.playBackgroundAudio({

    dataUrl:postsData.postList[currentPostId].music.url,

    title: postsData.postList[currentPostId].music.title,
    coverImgUrl: postsData.postList[currentPostId].music.coverImg

  })


  }
})